from PyQt5.QtCore import QThread, pyqtSignal, QDateTime
from PyQt5.QtWidgets import QApplication, QDialog, QLineEdit
import time
import sys
import datetime


class BackendThread(QThread):
    # 通过类成员对象定义信号
    update_date = pyqtSignal(str)
    # delay_date = pyqtSignal(str)

    # 处理业务逻辑
    def run(self):
        while True:
            data = QDateTime.currentDateTime()
            currTime = data.toString("yyyy-MM-dd hh:mm:ss")
            self.update_date.emit(str(currTime))
            # future_time = datetime.datetime.now() + datetime.timedelta(seconds=10)
            # self.delay_date.emit(str(future_time))
            time.sleep(1)


class Window(QDialog):
    def __init__(self):
        QDialog.__init__(self)
        self.setWindowTitle("PyQt 5界面实时更新例子")
        self.resize(400, 500)
        self.input = QLineEdit(self)
        self.input1 = QLineEdit(self)
        self.input.resize(400, 100)
        self.input1.resize(400, 100)
        self.input1.move(0, 100)
        self.initUI()

    def initUI(self):
        self.handleDisplay()

    # 将当前时间输出到文本框
    def handleDisplay(self):
        while True:
            data = QDateTime.currentDateTime()
            currTime = data.toString("yyyy-MM-dd hh:mm:ss")
            # future_time = datetime.datetime.now() + datetime.timedelta(seconds=10)
            # self.delay_date.emit(str(future_time))
            time.sleep(1)
            self.input.setText(currTime)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = Window()
    win.show()
    sys.exit(app.exec_())
